function [GG,RR,SDX,posAdded,ny,nx]=addMeasurementRow(posModel,loadModel,stdMeasurement,GG,RR,SDX) 
%
%% addMeasurementRow
%
% function [GG,RR,SDX,posAdded,ny,nx]=addMeasurementRow(posModel,loadModel,stdMeasurement,GG,RR,SDX) 
%
% Given the solution of the model, of the form 
% s_{t} = G s_{t-1} + R eta_{t} 
%
% V( eta ) = SDX'*SDX 
%
% add a row at the end of the form 
% sobs_{i,t}=load*s_{i,t}    + me(t) 
%           =load*G_{i,:}. s_{t-1} + load*R_{i,t}. eta_{t}  + me(t) 
% where the notation X_{i,:}. corresponds to the i-th row and me(t) is a
% measurement error 
% 
%% Inputs 
% *posModel* is the position of the original state in the
%            original G (i in the notation above) 
%
% *loadModel* loading to multiply the original state 
%
% *stdMeasurement*: std. dev of the measurement error me_{t} that will be
% appended to SDX 
% 
% GG,RR,SDX solution matrices and chol of covariance matrix 
%   
% 
%% Notes 
% Names are NOT modified here, should be done outside the function 
%
% A. Justiniano April 24 2014 
% =========================================================================

%% Original Dimensions 
nyOrig=size(GG,1); 
nxOrig=size(RR,2); 

posAdded=nyOrig+1; 

%% Add G row 
GG=blkdiag(GG,zeros(1));
GG(posAdded,:)=loadModel*GG(posModel,:); 
ny=size(GG,1); 

%% Add R Row 
RR=[RR zeros(nyOrig,1);zeros(1,nxOrig+1)]; 
RR(posAdded,:)=loadModel*RR(posModel,:); 
RR(posAdded,nxOrig+1)=1; 
nx=size(RR,2); 

%% Add SDX 
SDX=blkdiag(SDX,stdMeasurement); 

if size(SDX,2)~=nx 
    error('SDX and Number of shocks do not match'); 
end 